<template>
  <div>
    <van-cell title="选择单个日期" :value="date" @click="show = true" />
    <van-calendar v-model:show="show" @confirm="onConfirm" />
  </div>
</template>

<script setup>
import { ref, defineOptions } from "vue";

defineOptions({
  name: "MdCalendar",
});

const props = defineProps({
  item: {
    type: Object,
    default: () => {},
  },
});

const date = ref("");
const show = ref(false);

const formatDate = (date) => `${date.getMonth() + 1}/${date.getDate()}`;
const onConfirm = (value) => {
  show.value = false;
  date.value = formatDate(value);
};

// 向外暴露值
const getValue = () => {
  return {
    item: props.item,
    value: date.value,
  };
};

defineExpose({
  getValue,
});
</script>

<style lang="scss" scoped></style>
